import {ref,computed, onUnmounted} from "vue"
import dayjs from "dayjs"
export const useCountDown=()=>{

  // 1.响应式数据
  let formatTime=ref(0)
  let dsq=ref(0)
  // 2.方法
  const start=(currentTime)=>{
    formatTime.value=currentTime 
  dsq=  setInterval(()=>{
      formatTime.value--
    },1000)

  }

  
 let timedjs= computed(()=>{
      return dayjs.unix(formatTime.value).format("mm:ss")
  })

  onUnmounted(()=>{
    clearInterval(dsq.value)
  })
  
  return {
    formatTime,start,timedjs
  }
}